#Boa:Frame:MainFrame

#### MAIN FRAME ####

import wx
import MathFrame
import PiMath

def create(parent):
    return MainFrame(parent)

[wxID_MAINFRAME, wxID_MAINFRAMEBTN0, wxID_MAINFRAMEBTN1, wxID_MAINFRAMEBTN2, 
 wxID_MAINFRAMEBTN3, wxID_MAINFRAMEBTN4, wxID_MAINFRAMEBTN5, 
 wxID_MAINFRAMEBTN6, wxID_MAINFRAMEBTN7, wxID_MAINFRAMEBTN8, 
 wxID_MAINFRAMEBTN9, wxID_MAINFRAMEBTNBIND, wxID_MAINFRAMEBTNCLEAR, 
 wxID_MAINFRAMEBTNCOMMA, wxID_MAINFRAMEBTNCOS, wxID_MAINFRAMEBTNCPAREN, 
 wxID_MAINFRAMEBTNDIVIDE, wxID_MAINFRAMEBTNDOT, wxID_MAINFRAMEBTNENTER, 
 wxID_MAINFRAMEBTNLN, wxID_MAINFRAMEBTNLOG, wxID_MAINFRAMEBTNMATH, 
 wxID_MAINFRAMEBTNMINUS, wxID_MAINFRAMEBTNMULTIPLY, wxID_MAINFRAMEBTNOFF, 
 wxID_MAINFRAMEBTNOPAREN, wxID_MAINFRAMEBTNPLUS, wxID_MAINFRAMEBTNRAISE, 
 wxID_MAINFRAMEBTNSECOND, wxID_MAINFRAMEBTNSIN, wxID_MAINFRAMEBTNSQRT, 
 wxID_MAINFRAMEBTNTAN, wxID_MAINFRAMECCKDEGREEMODE, 
 wxID_MAINFRAMESTATICTEXTANSWER, wxID_MAINFRAMESTATICTEXTQUESTION, 
 wxID_MAINFRAMETXTANSWER, wxID_MAINFRAMETXTQUESTION, wxID_MAINFRAMETXTSECOND, 
] = [wx.NewId() for _init_ctrls in range(38)]

class MainFrame(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_MAINFRAME, name='', parent=prnt,
              pos=wx.Point(447, 157), size=wx.Size(399, 700),
              style=wx.DEFAULT_FRAME_STYLE, title='Pythonicalc')
        self.SetClientSize(wx.Size(391, 666))
        self.SetBackgroundColour(wx.Colour(228, 228, 228))
        self.SetBackgroundStyle(wx.BG_STYLE_COLOUR)
        self.Enable(True)
        self.SetExtraStyle(0)
        self.SetToolTipString('')
        self.SetIcon(wx.Icon("PiONEicon.ico", wx.BITMAP_TYPE_ICO))

        self.Btn1 = wx.Button(id=wxID_MAINFRAMEBTN1, label='1', name='Btn1',
              parent=self, pos=wx.Point(142, 476), size=wx.Size(30, 30),
              style=0)
        self.Btn1.SetToolTipString('')
        self.Btn1.Bind(wx.EVT_BUTTON, self.OnBtn1Click, id=wxID_MAINFRAMEBTN1)

        self.Btn2 = wx.Button(id=wxID_MAINFRAMEBTN2, label='2', name='Btn2',
              parent=self, pos=wx.Point(175, 476), size=wx.Size(30, 30),
              style=0)
        self.Btn2.SetToolTipString('')
        self.Btn2.Bind(wx.EVT_BUTTON, self.OnBtn2Click, id=wxID_MAINFRAMEBTN2)

        self.Btn3 = wx.Button(id=wxID_MAINFRAMEBTN3, label='3', name='Btn3',
              parent=self, pos=wx.Point(208, 476), size=wx.Size(30, 30),
              style=0)
        self.Btn3.SetToolTipString('')
        self.Btn3.Bind(wx.EVT_BUTTON, self.OnBtn3Click, id=wxID_MAINFRAMEBTN3)

        self.Btn4 = wx.Button(id=wxID_MAINFRAMEBTN4, label='4', name='Btn4',
              parent=self, pos=wx.Point(142, 443), size=wx.Size(30, 30),
              style=0)
        self.Btn4.SetToolTipString('')
        self.Btn4.Bind(wx.EVT_BUTTON, self.OnBtn4Click, id=wxID_MAINFRAMEBTN4)

        self.Btn5 = wx.Button(id=wxID_MAINFRAMEBTN5, label='5', name='Btn5',
              parent=self, pos=wx.Point(175, 443), size=wx.Size(30, 30),
              style=0)
        self.Btn5.SetToolTipString('')
        self.Btn5.Bind(wx.EVT_BUTTON, self.OnBtn5Click, id=wxID_MAINFRAMEBTN5)

        self.Btn6 = wx.Button(id=wxID_MAINFRAMEBTN6, label='6', name='Btn6',
              parent=self, pos=wx.Point(208, 443), size=wx.Size(30, 30),
              style=0)
        self.Btn6.SetToolTipString('')
        self.Btn6.Bind(wx.EVT_BUTTON, self.OnBtn6Click, id=wxID_MAINFRAMEBTN6)

        self.Btn7 = wx.Button(id=wxID_MAINFRAMEBTN7, label='7', name='Btn7',
              parent=self, pos=wx.Point(142, 410), size=wx.Size(30, 30),
              style=0)
        self.Btn7.SetToolTipString('')
        self.Btn7.Bind(wx.EVT_BUTTON, self.OnBtn7Click, id=wxID_MAINFRAMEBTN7)

        self.Btn8 = wx.Button(id=wxID_MAINFRAMEBTN8, label='8', name='Btn8',
              parent=self, pos=wx.Point(175, 410), size=wx.Size(30, 30),
              style=0)
        self.Btn8.SetToolTipString('')
        self.Btn8.Bind(wx.EVT_BUTTON, self.OnBtn8Click, id=wxID_MAINFRAMEBTN8)

        self.Btn9 = wx.Button(id=wxID_MAINFRAMEBTN9, label='9', name='Btn9',
              parent=self, pos=wx.Point(208, 410), size=wx.Size(30, 30),
              style=0)
        self.Btn9.SetToolTipString('')
        self.Btn9.Bind(wx.EVT_BUTTON, self.OnBtn9Click, id=wxID_MAINFRAMEBTN9)

        self.Btn0 = wx.Button(id=wxID_MAINFRAMEBTN0, label='0', name='Btn0',
              parent=self, pos=wx.Point(142, 509), size=wx.Size(30, 30),
              style=0)
        self.Btn0.SetToolTipString('')
        self.Btn0.Bind(wx.EVT_BUTTON, self.OnBtn0Click, id=wxID_MAINFRAMEBTN0)

        self.BtnDot = wx.Button(id=wxID_MAINFRAMEBTNDOT, label='.',
              name='BtnDot', parent=self, pos=wx.Point(175, 509),
              size=wx.Size(30, 30), style=0)
        self.BtnDot.SetToolTipString('')
        self.BtnDot.Bind(wx.EVT_BUTTON, self.OnBtnDotClick,
              id=wxID_MAINFRAMEBTNDOT)

        self.BtnEnter = wx.Button(id=wxID_MAINFRAMEBTNENTER, label='Solve',
              name='BtnEnter', parent=self, pos=wx.Point(208, 542),
              size=wx.Size(63, 30), style=0)
        self.BtnEnter.SetToolTipString('')
        self.BtnEnter.Bind(wx.EVT_BUTTON, self.OnBtnEnterClick,
              id=wxID_MAINFRAMEBTNENTER)

        self.BtnPlus = wx.Button(id=wxID_MAINFRAMEBTNPLUS, label='+',
              name='BtnPlus', parent=self, pos=wx.Point(241, 377),
              size=wx.Size(30, 30), style=0)
        self.BtnPlus.SetToolTipString('')
        self.BtnPlus.Bind(wx.EVT_BUTTON, self.OnBtnPlusClick,
              id=wxID_MAINFRAMEBTNPLUS)

        self.BtnMinus = wx.Button(id=wxID_MAINFRAMEBTNMINUS, label='-',
              name='BtnMinus', parent=self, pos=wx.Point(241, 410),
              size=wx.Size(30, 30), style=0)
        self.BtnMinus.SetToolTipString('')
        self.BtnMinus.Bind(wx.EVT_BUTTON, self.OnBtnMinusClick,
              id=wxID_MAINFRAMEBTNMINUS)

        self.BtnRaise = wx.Button(id=wxID_MAINFRAMEBTNRAISE, label='^',
              name='BtnRaise', parent=self, pos=wx.Point(241, 509),
              size=wx.Size(30, 30), style=0)
        self.BtnRaise.SetToolTipString('')
        self.BtnRaise.Bind(wx.EVT_BUTTON, self.OnBtnRaiseClick,
              id=wxID_MAINFRAMEBTNRAISE)

        self.BtnDivide = wx.Button(id=wxID_MAINFRAMEBTNDIVIDE, label='/',
              name='BtnDivide', parent=self, pos=wx.Point(241, 476),
              size=wx.Size(30, 30), style=0)
        self.BtnDivide.SetToolTipString('')
        self.BtnDivide.Bind(wx.EVT_BUTTON, self.OnBtnDivideClick,
              id=wxID_MAINFRAMEBTNDIVIDE)

        self.BtnMultiply = wx.Button(id=wxID_MAINFRAMEBTNMULTIPLY, label='*',
              name='BtnMultiply', parent=self, pos=wx.Point(241, 443),
              size=wx.Size(30, 30), style=0)
        self.BtnMultiply.SetToolTipString('')
        self.BtnMultiply.Bind(wx.EVT_BUTTON, self.OnBtnMultiplyClick,
              id=wxID_MAINFRAMEBTNMULTIPLY)

        self.BtnOParen = wx.Button(id=wxID_MAINFRAMEBTNOPAREN, label='(',
              name='BtnOParen', parent=self, pos=wx.Point(142, 542),
              size=wx.Size(30, 30), style=0)
        self.BtnOParen.SetToolTipString('')
        self.BtnOParen.Bind(wx.EVT_BUTTON, self.OnBtnOParenClick,
              id=wxID_MAINFRAMEBTNOPAREN)

        self.BtnCParen = wx.Button(id=wxID_MAINFRAMEBTNCPAREN, label=')',
              name='BtnCParen', parent=self, pos=wx.Point(175, 542),
              size=wx.Size(30, 30), style=0)
        self.BtnCParen.SetToolTipString('')
        self.BtnCParen.Bind(wx.EVT_BUTTON, self.OnBtnCParenClick,
              id=wxID_MAINFRAMEBTNCPAREN)

        self.BtnComma = wx.Button(id=wxID_MAINFRAMEBTNCOMMA, label=',',
              name='BtnComma', parent=self, pos=wx.Point(208, 509),
              size=wx.Size(30, 30), style=0)
        self.BtnComma.SetToolTipString('')
        self.BtnComma.Bind(wx.EVT_BUTTON, self.OnBtnCommaClick,
              id=wxID_MAINFRAMEBTNCOMMA)

        self.BtnLn = wx.Button(id=wxID_MAINFRAMEBTNLN, label='ln', name='BtnLn',
              parent=self, pos=wx.Point(109, 476), size=wx.Size(30, 30),
              style=0)
        self.BtnLn.SetToolTipString('2cd: e^x')
        self.BtnLn.Bind(wx.EVT_BUTTON, self.OnBtnLnClick,
              id=wxID_MAINFRAMEBTNLN)

        self.BtnLog = wx.Button(id=wxID_MAINFRAMEBTNLOG, label='log',
              name='BtnLog', parent=self, pos=wx.Point(109, 443),
              size=wx.Size(30, 30), style=0)
        self.BtnLog.SetToolTipString('2cd: 10^x')
        self.BtnLog.Bind(wx.EVT_BUTTON, self.OnBtnLogClick,
              id=wxID_MAINFRAMEBTNLOG)

        self.BtnSqrt = wx.Button(id=wxID_MAINFRAMEBTNSQRT, label='sqrt',
              name='BtnSqrt', parent=self, pos=wx.Point(109, 410),
              size=wx.Size(30, 30), style=0)
        self.BtnSqrt.SetToolTipString('2cd: x^2')
        self.BtnSqrt.Bind(wx.EVT_BUTTON, self.OnBtnSqrtClick,
              id=wxID_MAINFRAMEBTNSQRT)

        self.BtnSin = wx.Button(id=wxID_MAINFRAMEBTNSIN, label='sin',
              name='BtnSin', parent=self, pos=wx.Point(142, 377),
              size=wx.Size(30, 30), style=0)
        self.BtnSin.SetToolTipString('2cd: asin')
        self.BtnSin.Bind(wx.EVT_BUTTON, self.OnBtnSinClick,
              id=wxID_MAINFRAMEBTNSIN)

        self.BtnCos = wx.Button(id=wxID_MAINFRAMEBTNCOS, label='cos',
              name='BtnCos', parent=self, pos=wx.Point(175, 377),
              size=wx.Size(30, 30), style=0)
        self.BtnCos.SetToolTipString('2nd: acos')
        self.BtnCos.Bind(wx.EVT_BUTTON, self.OnBtnCosClick,
              id=wxID_MAINFRAMEBTNCOS)

        self.BtnTan = wx.Button(id=wxID_MAINFRAMEBTNTAN, label='tan',
              name='BtnTan', parent=self, pos=wx.Point(208, 377),
              size=wx.Size(30, 30), style=0)
        self.BtnTan.SetToolTipString('2nd: atan')
        self.BtnTan.Bind(wx.EVT_BUTTON, self.OnBtnTanClick,
              id=wxID_MAINFRAMEBTNTAN)

        self.BtnSet = wx.Button(id=wxID_MAINFRAMEBTNBIND, label='Set',
              name='BtnSet', parent=self, pos=wx.Point(109, 509),
              size=wx.Size(30, 30), style=0)
        self.BtnSet.SetToolTipString('')
        self.BtnSet.Bind(wx.EVT_BUTTON, self.OnBtnSetClick,
              id=wxID_MAINFRAMEBTNBIND)

        self.BtnMath = wx.Button(id=wxID_MAINFRAMEBTNMATH, label='Math',
              name='BtnMath', parent=self, pos=wx.Point(109, 377),
              size=wx.Size(30, 30), style=0)
        self.BtnMath.SetToolTipString('')
        self.BtnMath.Bind(wx.EVT_BUTTON, self.OnBtnMathClick,
              id=wxID_MAINFRAMEBTNMATH)

        self.BtnClear = wx.Button(id=wxID_MAINFRAMEBTNCLEAR, label='C',
              name='BtnClear', parent=self, pos=wx.Point(241, 344),
              size=wx.Size(30, 30), style=0)
        self.BtnClear.SetToolTipString('')
        self.BtnClear.Bind(wx.EVT_BUTTON, self.OnBtnClearClick,
              id=wxID_MAINFRAMEBTNCLEAR)

        self.BtnSecond = wx.Button(id=wxID_MAINFRAMEBTNSECOND, label='2cd',
              name='BtnSecond', parent=self, pos=wx.Point(109, 344),
              size=wx.Size(30, 30), style=0)
        self.BtnSecond.SetToolTipString('')
        self.BtnSecond.Bind(wx.EVT_BUTTON, self.OnBtnSecondClick,
              id=wxID_MAINFRAMEBTNSECOND)

        self.BtnOff = wx.Button(id=wxID_MAINFRAMEBTNOFF, label='Off',
              name='BtnOff', parent=self, pos=wx.Point(109, 542),
              size=wx.Size(30, 30), style=0)
        self.BtnOff.SetToolTipString('')
        self.BtnOff.Bind(wx.EVT_BUTTON, self.OnBtnOffClick,
              id=wxID_MAINFRAMEBTNOFF)

        self.TxtQuestion = wx.TextCtrl(id=wxID_MAINFRAMETXTQUESTION,
              name='textCtrl1', parent=self, pos=wx.Point(8, 24),
              size=wx.Size(376, 200), style=wx.TE_MULTILINE, value='')
        self.TxtQuestion.SetToolTipString('')
        self.TxtQuestion.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, 'Lucida Console'))

        self.staticTextQuestion = wx.StaticText(id=wxID_MAINFRAMESTATICTEXTQUESTION,
              label='QUESTION:', name='staticTextQuestion', parent=self,
              pos=wx.Point(8, 8), size=wx.Size(70, 13), style=0)
        self.staticTextQuestion.SetToolTipString('')

        self.TxtAnswer = wx.TextCtrl(id=wxID_MAINFRAMETXTANSWER,
              name='TxtAnswer', parent=self, pos=wx.Point(75, 232),
              size=wx.Size(311, 21), style=wx.ALIGN_RIGHT, value='')
        self.TxtAnswer.SetToolTipString('')

        self.staticTextAnswer = wx.StaticText(id=wxID_MAINFRAMESTATICTEXTANSWER,
              label='ANSWER:', name='staticTextAnswer', parent=self,
              pos=wx.Point(11, 235), size=wx.Size(60, 13), style=0)
        self.staticTextAnswer.SetToolTipString('')

        self.TxtSecond = wx.StaticText(id=wxID_MAINFRAMETXTSECOND, label='2cd',
              name='TxtSecond', parent=self, pos=wx.Point(367, 6),
              size=wx.Size(17, 13), style=0)

        self.CckDegreeMode = wx.CheckBox(id=wxID_MAINFRAMECCKDEGREEMODE,
              label='Degree Mode', name='CckDegreeMode', parent=self,
              pos=wx.Point(295, 637), size=wx.Size(86, 13), style=0)
        self.CckDegreeMode.SetValue(False)
        self.CckDegreeMode.Bind(wx.EVT_CHECKBOX, self.OnCckDegreeStateChange,
              id=wxID_MAINFRAMECCKDEGREEMODE)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.TxtQuestion.SetFocus()
        self.TxtSecond.SetLabel("")

#==============================================================================================================

    #Initiate SecondOn as False.
    #   This will keep track of whether the user has the "second" option on.
    SecondOn = False

    def ElementClick(self, elem):
        """ElementClick(elem): puts emlem in the equation box. Clears 2nd"""
        self.TxtQuestion.WriteText(elem)
        #If the user clicked the "2cd" button, reset it
        self.SecondOn = False
        self.TxtSecond.SetLabel("")
        self.TxtQuestion.SetFocus()

    def FunctionClick(self, nrml, nrmlSrnd, invrs, invrsSrnd):
        """FunctionClick(nrml, nrmlSrnd, invrs, invrsSrnd): if no selection,
           puts the normal function into the equation box.  If there is a selection,
           the selection is surrounded by the function, with nrmlSrnd being the closing
           string.  If 2nd is on, the same is done with the inverse function."""
        #Sel[0] is the index of the first character in the user's selection
        #   Sel[1] is the index of the last character in the users' selection.
        if self.SecondOn == False:
            Sel = self.TxtQuestion.GetSelection()
            if Sel[0] == Sel[1]:
            #If the user doesn't select anything, just insert a NoRMaL function.
                self.TxtQuestion.WriteText(nrml)
            else:
            #Otherwise, call the Surround function, which will surround the selection
            #   with perentheses.
                self.Surround(nrml, nrmlSrnd)
        else:
            #And if the 2nd button is on, do the INVeRSe function.
            Sel = self.TxtQuestion.GetSelection()
            if Sel[0] == Sel[1]:
                self.TxtQuestion.WriteText(invrs)
            else:
                self.Surround(invrs, invrsSrnd)
            self.SecondOn = False
            self.TxtSecond.SetLabel("")
        self.TxtQuestion.SetFocus()

    def Surround(self, BeforeStr, AfterStr):
        """Surround(BeforeStr, AfterStr): Surrounds the selection with 
            the appropriate function."""
        #Get the index of the first and last characters in the selction
        Sel = self.TxtQuestion.GetSelection()
        #If BeforeStr was "ln(", AfterStr was ")", and the user had selected
        #   the number 35, ChangeTo would be the string "ln(35)"
        ChangeTo = BeforeStr + "".join(self.TxtQuestion.GetRange(Sel[0], Sel[1]).split()) + AfterStr
        #BeforeNums will equal the indecies of the first character in the TxtQuestion
        #   box, and of the character before the user's selection.
        BeforeNums = self.TxtQuestion.SetSelection(0, Sel[0])
        BeforeNums = self.TxtQuestion.GetSelection()
        #Before will equal the string before the user's selection
        Before = "".join(self.TxtQuestion.GetRange(BeforeNums[0], BeforeNums[1]).split())
        #AfterNums will equal the indecies of the character after the user's selection,
        #   and of the final character in teh TxtQuestion Box.
        AfterNums = self.TxtQuestion.SetSelection(Sel[1], -1)
        AfterNums = self.TxtQuestion.GetSelection()
        #After will equal the string after the user's selection
        After = "".join(self.TxtQuestion.GetRange(AfterNums[0], AfterNums[1]).split())
        #Replace what's in the text box with the changed text.
        self.TxtQuestion.SetValue(Before + ChangeTo + After)
        #Set's the selection to the user's original selection.
        #   Sometimes this messes up if the user selects a control character
        #   in his selection.
        self.TxtQuestion.SetSelection(Sel[0]+len(BeforeStr), Sel[1]+len(BeforeStr))

    def OnBtn1Click(self, event):
        self.ElementClick("1")
    def OnBtn2Click(self, event):
        self.ElementClick("2")
    def OnBtn3Click(self, event):
        self.ElementClick("3") 
    def OnBtn4Click(self, event):
        self.ElementClick("4")
    def OnBtn5Click(self, event):
        self.ElementClick("5")
    def OnBtn6Click(self, event):
        self.ElementClick("6")
    def OnBtn7Click(self, event):
        self.ElementClick("7")
    def OnBtn8Click(self, event):
        self.ElementClick("8")
    def OnBtn9Click(self, event):
        self.ElementClick("9")
    def OnBtn0Click(self, event):
        self.ElementClick("0")
    def OnBtnDotClick(self, event):
        self.ElementClick(".")
    def OnBtnPlusClick(self, event):
        self.ElementClick("+")
    def OnBtnMinusClick(self, event):
        self.ElementClick("-")
    def OnBtnMultiplyClick(self, event):
        self.ElementClick("*")
    def OnBtnDivideClick(self, event):
        self.ElementClick("/")
    def OnBtnRaiseClick(self, event):
        self.ElementClick("^")
    def OnBtnCParenClick(self, event):
        self.ElementClick(")")
    def OnBtnCommaClick(self, event):
        self.ElementClick(",")
    def OnBtnSetClick(self, event):
        self.ElementClick("=")

    def OnBtnLnClick(self, event):
        self.FunctionClick("ln(", ")", "e^(", ")")
    def OnBtnLogClick(self, event):
        self.FunctionClick("log(", ")", "10^(", ")")
    def OnBtnSqrtClick(self, event):
        self.FunctionClick("sqrt(", ")", "(", ")^2")
    def OnBtnSinClick(self, event):
        self.FunctionClick("sin(", ")", "asin(", ")")
    def OnBtnCosClick(self, event):
        self.FunctionClick("cos(", ")", "acos(", ")")
    def OnBtnTanClick(self, event):
        self.FunctionClick("tan(", ")", "atan(", ")")

    def OnBtnOParenClick(self, event):
        Sel = self.TxtQuestion.GetSelection()
        if Sel[0] == Sel[1]:
            self.TxtQuestion.WriteText("(")
        else:
            self.Surround("(", ")")
        self.SecondOn = False
        self.TxtSecond.SetLabel("")
        self.TxtQuestion.SetFocus()

    def OnBtnClearClick(self, event):
        self.SecondOn = False
        self.TxtSecond.SetLabel("")
        self.TxtQuestion.SetValue("")
        self.TxtAnswer.SetValue("")
        self.TxtQuestion.SetFocus()

    def OnBtnSecondClick(self, event):
        if self.SecondOn == False:
            self.SecondOn = True
            self.TxtSecond.SetLabel("2cd")
        else:
            self.SecondOn = False
            self.TxtSecond.SetLabel("")
        self.TxtQuestion.SetFocus()

    def OnCckDegreeStateChange(self, event):
        PiMath.DegreeMode = self.CckDegreeMode.GetValue()
        self.TxtQuestion.SetFocus()

    #SOLVE BUTTON
    def OnBtnEnterClick(self, event):
        self.SecondOn = False
        self.TxtSecond.SetLabel("")
        self.TxtAnswer.SetValue("")
        Equation = self.TxtQuestion.GetValue()
        Answer = PiMath.Evaluate(Equation)
        self.TxtAnswer.SetValue(str(Answer))
        self.TxtQuestion.SetFocus()
    
    #MATH BUTTON
    def OnBtnMathClick(self, event):
        global MathFrame
        self.SecondOn = False
        self.TxtSecond.SetLabel("")
        if not MathFrame.IsRunning:
            self.MathFrame = MathFrame.create(self)
            self.MathFrame.Show()
            self.MathFrame.SetIcon(wx.Icon("PiONEicon.ico", wx.BITMAP_TYPE_ICO))

    #OFF BUTTON
    def OnBtnOffClick(self, event):
        self.SecondOn = False
        self.TxtSecond.SetLabel("")
        #Is the MessageBox too much?
        WillExit = wx.MessageBox("Are you sure you want to exit?", "Exit Program", style=wx.YES_NO)
        if WillExit == wx.YES:
            wx.Exit()
